import MySQLdb
#from pyPgSQL import PgSQL


class Banco():
    
    def __init__(self):
        
        self.host       = ""
        self.usuario    = ""
        self.senha      = ""
        self.nome       = ""
        self.tipo       = ""
        
    def __getattr__(self, name):

        if name == "host":
            return self.host
        
        elif name == "usuario":
            return self.usuario

        elif name == "senha":
            return self.senha

        elif name == "nome":
            return self.nome

        elif name == "tipo":
            return self.tipo
        
        else:
            raise AttributeError, name


    def __setattr__(self, name, value):

        if name == "host":
            self.__dict__["host"]   = value

        elif name == "usuario":
            self.__dict__["usuario"]   = value

        elif name == "senha":
            self.__dict__["senha"]     = value

        elif name == "nome":
            self.__dict__["nome"]     = value

        elif name == "tipo":
            self.__dict__["tipo"]     = value
            
        else:
            raise AttributeError, name
            

    def executa_query_Mysql(self, query):
        
        if self.__getattr__('tipo') == "Mysql":
            
            host       = self.__getattr__('host')
            usuario    = self.__getattr__('usuario')
            senha      = self.__getattr__('senha')
            nome       = self.__getattr__('nome')
            
            conn = MySQLdb.connect(host = host,  user = usuario, passwd = senha, db = nome)
            cursor = conn.cursor()
            cursor.execute(query) 

            cursor.close()
            conn.close()
    
#    def executa_query_Postgre(self, query):
#        
#        if self.__getattr__('tipo') == "Postgre":
#            
#            host       = self.__getattr__('host')
#            usuario    = self.__getattr__('usuario')
#            senha      = self.__getattr__('senha')
#            nome       = self.__getattr__('nome')
#            
#            conn = PgSQL.connect(host=host, database=nome, user=usuario, password=senha)
#            cursor = conn.cursor()
#            cursor.execute(query)
#            
#            cursor.close()
#            conn.close()            
        
        
        
        
        
        
        

        
